import { setItem, deleteItem, getItem } from '@/utils/localStorege'
import { Login } from '@/api/login'
export default {
  namespaced: true,
  state: () => {
    return {
      token: getItem() || ''
    }
  },
  mutations: {
    SAVE_TOKEN (state, val) {
      state.token = val
      setItem(val)
    },
    DELE_TOKEN (state) {
      state.token = ''
      deleteItem()
    }
  },
  actions: {
    async  login ({ commit }, value) {
      const { data } = await Login(value)
      commit('SAVE_TOKEN', data)
    }
  }
}
